#e
#Title[guׂĂeɂȂv]
#Text[]
#Image[]
#BackGround[]
#BGM[]
#PlayLevel[Extra]
#ScriptVersion[2]
#Player[FREE]

script_enemy_main
{
let wt=80;
let usebomb=0;

	//GoɈxs镔
	@Initialize
	{
	//   eϐ

	//   XyJ[hf[^
	SetLife(1000);
	SetScore(200000);
	SetDamageRate(30,  0);
	SetTimer(78);
	SetInvincibility(120);
	SetShotAutoDeleteClip(128,128,128,128);
	LoadGraphic("script\img\ExRumia.png");
	CutIn(KOUMA,"guׂĂeɂȂv",GetCurrentScriptDirectory~"..\img\cutin06.png",0,0,255,320);
	}
	//   ʒu܂ňړ
	SetMovePosition02(GetCenterX, GetCenterY-80, 60);
	
	BG_Standard;
	AtackTask;
	MoveTask;
	ControlTask;
	//G̃Ct0ɂȂ܂ŁA̕1t[1s
	@MainLoop
	{
		yield;

		if(OnBomb==false){
			SetCollisionA(GetX, GetY, 32);
			SetCollisionB(GetX, GetY, 24);
			usebomb=0;
		}
		else{
			usebomb++;
		}
		if(usebomb==1){
			BombBarrier;
		}

	}
	
	//`惋[vB1t[1s
	@DrawLoop
	{
		SetGraphicRect(0,1,63,64);
		if(GetSpeedX<0){
			SetGraphicRect(128,1,191,64);
		}
		if(GetSpeedX>0){
			SetGraphicRect(192,1,255,64);
		}
		SetColor(255,255,255);
		SetAlpha(255);
		if(OnBomb==true){SetAlpha(96);}
		SetTexture("script\img\ExRumia.png");//摜͔q
		DrawGraphic(GetX(),GetY());//G̍WEx[~A`;
	}
		
	//GłuԂɈxs镔
	@Finalize
	{
		DeleteGraphic("script\img\ExRumia.png");
		DeleteGraphic(GetCurrentScriptDirectory ~"..img\back1.png");
		DeleteGraphic(GetCurrentScriptDirectory ~"..img\back2.png");
	}
	//XyJ[h̔wi
	//Ă悢
	@BackGround
	{
		BG_Simple;
	}

	task AtackTask{
		wait(120);

		//e
		let aax=[0,1,2,3,4,5,6,7,8,0,0,0,0,0,1,2,3,4,5,6,0,0,0,0,0];
		let aay=[0,0,0,0,0,0,0,0,0,1,2,3,4,5,5,5,5,5,5,5,6,7,8,9,10];
		let i=0;
		let ptn=0;		//ǂ̕ɏo邩B
		let scale=5;	//AA̒e̊Ԋu
		let x=0;		//ˍW
		let y=0;
		let txbase=GetCenterX-100;		//ʒuAW
		let tybase=GetCenterY-35;
		let passtime=240;				//AA
		let afterspd=2;
		let afterdir=90;
		let grf=RED01;
		let delay=60;

		while(true){
			x=0;
			y=0;
			i=0;
			txbase=rand(GetCenterX-200,GetCenterX+200);
			tybase=rand(GetCenterY-100,GetCenterY+100);
			afterspd=1.5;
			scale=rand(4,16);
			afterdir=atan2(GetCenterY-(tybase+scale*4),GetCenterX-(txbase+scale*4));//atan2(GetPlayerY-(tybase+scale*4),GetPlayerX-(txbase+scale*4));
			ascent(i in 0..length(aax)){
				ptn=rand_int(0,3);
				alternative(ptn)
				case(0){
					x=GetClipMinX;
					y=rand(GetClipMinY,GetClipMaxY);
				}
				case(1){
					x=rand(GetClipMinX,GetClipMaxX);
					y=GetClipMinY;
				}
				case(2){
					x=GetClipMaxX;
					y=rand(GetClipMinY,GetClipMaxY);
				}
				case(3){
					x=rand(GetClipMinX,GetClipMaxX);
					y=GetClipMaxY;
				}
				PointPassShotB(x,y,aax[i]*scale+txbase,aay[i]*scale+tybase,passtime,afterspd,afterdir,grf,delay);
			}
			wait(wt);
			x=0;
			y=0;
			i=0;
			txbase=rand(GetCenterX-150,GetCenterX+150);
			tybase=rand(GetCenterY-200,GetCenterY);
			afterspd=1.5;
			scale=rand(4,16);
			afterdir=atan2(GetCenterY-(tybase+scale*4),GetCenterX-(txbase+scale*4));//atan2(GetPlayerY-(tybase+scale*4),GetPlayerX-(txbase+scale*4));
			ascent(i in 0..length(aax)){
				ptn=rand_int(0,3);
				alternative(ptn)
				case(0){
					x=GetClipMinX;
					y=rand(GetClipMinY,GetClipMaxY);
				}
				case(1){
					x=rand(GetClipMinX,GetClipMaxX);
					y=GetClipMinY;
				}
				case(2){
					x=GetClipMaxX;
					y=rand(GetClipMinY,GetClipMaxY);
				}
				case(3){
					x=rand(GetClipMinX,GetClipMaxX);
					y=GetClipMaxY;
				}
				PointPassShotB(x,y,aax[i]*scale+txbase,aay[i]*scale+tybase,passtime,afterspd,afterdir,grf,delay);
			}
			wait(wt);
		}
	}
	task MoveTask{
		wait(120);
		while(true){
			SetMovePosition02(rand(GetClipMinX+60,GetCenterX-60), rand(GetClipMinY+60,GetCenterY-80), 80);
			wait(180);
			SetMovePosition02(rand(GetCenterX-60,GetCenterX+60), rand(GetClipMinY+60,GetCenterY-80), 80);
			wait(180);
			SetMovePosition02(rand(GetCenterX+60,GetClipMaxX-60), rand(GetClipMinY+60,GetCenterY-80), 80);
			wait(180);
			SetMovePosition02(rand(GetCenterX-60,GetCenterX+60), rand(GetClipMinY+60,GetCenterY-80), 80);
			wait(180);
		}
	}
	task ControlTask{
		wait(250);
		while(GetEnemyLife>600&&GetTimer>20){yield;}
		wt=70;
		while(GetEnemyLife>600&&GetTimer>20){yield;}
		wt=60;
		while(GetEnemyLife>400&&GetTimer>20){yield;}
		wt=50;
		while(GetEnemyLife>200&&GetTimer>20){yield;}
		wt=40;
		while(GetTimer>20){yield;}
		wt=30;
	}


	function PointPassShotB(	//ڕWWw莞Ԃɒʉ߂鑬xƊpxŔ˂e
					//w莞Ԃɕ]
		x,		//ˍW
		y,
		tx,		//ڕWW
		ty,
		passtime,	//ʉߎ(ZĂĂǂȂ)
		afterspd,	//]̑x
		afterdir,	//]̊px
		grf,	//OtBbN
		delay	//fBC
	)
	{
		let xspd=(tx-x)/passtime;
		let yspd=(ty-y)/passtime;
		CreateShotA(0,x,y,delay);
		SetShotDataA_XY(0,0,xspd,yspd,0,0,0,0,grf);
		SetShotDataA(0,passtime,afterspd,afterdir,0,0,0,grf);
		FireShot(0);
	}

	#include_function".\function.txt"
}
